package com.enation.app.javashop.api.client;

import com.enation.app.javashop.model.aftersale.dos.RefundDO;
import com.enation.app.javashop.model.aftersale.vo.ApplyAfterSaleVO;
import com.enation.app.javashop.model.goods.enums.Permission;
import com.enation.app.javashop.service.aftersale.AfterSaleManager;
import com.enation.app.javashop.service.aftersale.AfterSaleQueryManager;
import com.enation.app.javashop.service.aftersale.AfterSaleRefundManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 售后client
 * @author kingapex
 * @version 1.0
 * @since 7.1.0
 * 2020/4/9
 */
@RestController
@RequestMapping("/client/after-sale")
@Validated
@ApiIgnore
public class AfterSaleClientController {

    @Autowired
    protected AfterSaleManager afterSaleManager;

    @Autowired
    private AfterSaleQueryManager afterSaleQueryManager;

    @Autowired
    private AfterSaleRefundManager afterSaleRefundManager;


    /**
     * 退款完成
     */
    @GetMapping("/refund-completion")
    public void refundCompletion() {
        afterSaleManager.refundCompletion();
    }


    @PutMapping("/order/{order_sn}/cancel")
    public void cancelPintuanOrder(@PathVariable("order_sn") String orderSn, @RequestParam("cancel_reason") String cancelReason) {
        afterSaleManager.cancelPintuanOrder(orderSn, cancelReason);
    }

    @GetMapping("/service/{service_sn}")
    public ApplyAfterSaleVO detail(@PathVariable("service_sn") String serviceSn) {
        return afterSaleQueryManager.detail(serviceSn, Permission.CLIENT);
    }

    @GetMapping("/refund/{service_sn}")
    public RefundDO getAfterSaleRefundModel(@PathVariable("service_sn") String serviceSn) {
        return afterSaleRefundManager.getModel(serviceSn);
    }


    @PutMapping("/shop/{shop_id}/name")
    public void editAfterSaleShopName(@PathVariable("shop_id")Long shopId, @RequestParam("shop_name")String shopName) {
        afterSaleManager.editAfterSaleShopName(shopId, shopName);
    }

}
